#ifndef INC_02_SELECTION_SORT_USING_TEMPLATE_TESTSORTHELPER
#define INC_02_SELECTION_SORT_USING_TEMPLATE_TESTSORTHELPER

#include <iostream>
#include <string>
#include <ctime>
#include <cassert>
using namespace std;
namespace TestSortHelper {
	int * generateRandomArray(int n, int rangeL, int rangeR) {
		assert(rangeR > rangeL);
		int *arr = new int[n];
		srand(time(NULL));
		for (int i = 0;i < n; i++) {
			arr[i] = rand() % (rangeR - rangeL+1) + rangeL;
		}
		return arr;
	}

	int * generateNearlyOrderedArray(int n, int swaptimes) {
		int *arr = new int[n];
		for (int i = 0;i < n; i++) {
			arr[i] = i;
		}
		srand(time(NULL));
		while (swaptimes-- > 0) {
			int i1 = rand() % (n);
			int i2 = rand() % (n);
			swap(arr[i1],arr[i2]);
		}

		return arr;
	}

	int * copyIntArray(const int arr[], int n) {
		int *copyArr = new int[n];
		for (int i = 0;i < n; i++) {
			copyArr[i] = arr[i];
		}
		return copyArr;
	}


	template<typename T>
	void printArray(T arr[], int n) {
		for (int i = 0; i < n; i++) {
			cout << arr[i] << " ";
		}
		cout << endl;
		return;
	}

	template<typename T>
	bool isSorted(T arr[], int n) {
		for (int i = 1; i < n;i++) {
			if (arr[i] < arr[i - 1])
				return false;
		}
		return true;
	}

	template<typename T>
	void testSort(string sortName, void(*sort)(T[], int), T arr[], int n) {
		clock_t startTime = clock();
		sort(arr, n);
		clock_t endTime = clock();
		assert(isSorted(arr, n));
		cout << sortName << ":" << double(endTime - startTime) / CLOCKS_PER_SEC << " s" << endl;

	}

}
#endif